//
//  QJDetailVCHeaderOne.m
//  QuanJieShopProject
//
//  Created by apple on 2018/1/31.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJDetailVCHeaderOne.h"
//轮播图
#import <SDCycleScrollView.h>
@interface QJDetailVCHeaderOne ()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView *cycleView;
@end
@implementation QJDetailVCHeaderOne
-(void)headerUIPrepareAction{
    
    // 这里搞个 scrollView 干什么? 有点乱
    self.scrollView.backgroundColor = [UIColor whiteColor];
    
    self.cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_WIDTH) delegate:self placeholderImage:[UIImage imageNamed:@""]];
    self.cycleView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:self.cycleView];
    
    self.scrollViewH.constant =  self.cycleView.mj_w;
    NSLog(@"h = %f, w =%f", _scrollView.mj_h, _scrollView.mj_w);
    self.mj_h = UISCREEN_WIDTH + 155;
}
-(void)headerUpdateWithDic:(NSDictionary *)dict{
    self.dataDic = dict;
    
    
    NSDictionary *data = dict[@"data"];
    NSDictionary *shopDict = data[@"goods"];
    NSLog(@"shopDict === %@", shopDict);

    self.priceLabel.text = [NSString stringWithFormat:@"¥%@", shopDict[@"shop_price"]];
    self.buyCountLabel.text = [NSString stringWithFormat:@"%@人已买", shopDict[@"sales_sum"]];
    self.collectionCountLabel.text = [NSString stringWithFormat:@"%@人已收藏", shopDict[@"is_collect"]];
    self.titleLabel.text = shopDict[@"goods_name"];
    self.stockLabel.text = [NSString stringWithFormat:@"库存%@", shopDict[@"store_count"]];
    self.freightLabel.text = @"卖家承担费用";

    /*
     
     @property (weak, nonatomic) IBOutlet UILabel *stockLabel; // 库存
     @property (weak, nonatomic) IBOutlet UILabel *freightLabel;    // 运费*/
    
    NSMutableArray *array = [NSMutableArray array];
    NSArray *arr = data[@"goods_images_list"];
    NSLog(@"arr = %@", arr);
    for (int i = 0; i < arr.count; i++) {
        NSDictionary *dict = arr[i];
        NSString *bannerUrl = [NSString stringWithFormat:@"%@",dict[@"image_url"]];
        NSLog(@"bannerUrl = %@", bannerUrl);
        [array addObject:bannerUrl];
    }
    self.cycleView.imageURLStringsGroup = array;
    self.cycleView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
 
}
- (IBAction)jianBtnClickAction:(UIButton *)sender {
//    if ([self.headerNumLabel.text isEqualToString:@"1"]) {
//        [MBPHUD showAlertWithTitle:@"商品数量不可为0!"];
//    }else{
//        NSInteger num = [self.headerNumLabel.text integerValue];
//        num = num - 1;
//        self.headerNumLabel.text = [NSString stringWithFormat:@"%ld",(long)num];
//        if (num == 1) {
//            [self.headerJBtn setImage:[UIImage imageNamed:@"SDjiangray"] forState:UIControlStateNormal];
//        }
//        if (self.changeShopNumberBlock) {
//            self.changeShopNumberBlock(num);
//        }
//    }
}
- (IBAction)addBtnClickAction:(UIButton *)sender {
//    if ([self.headerNumLabel.text isEqualToString:@"1"]) {
//        [self.headerJBtn setImage:[UIImage imageNamed:@"SDjian"] forState:UIControlStateNormal];
//    }
//    NSInteger num = [self.headerNumLabel.text integerValue];
//    NSInteger kc = 1;
//    kc = [self.dataDic[@"stock"] integerValue];
//    if (num < kc) {
//        num = num + 1;
//        self.headerNumLabel.text = [NSString stringWithFormat:@"%ld",num];
//        if (self.changeShopNumberBlock) {
//            self.changeShopNumberBlock(num);
//        }
//    }else{
//        [MBPHUD showAlertWithTitle:@"商品库存不足!"];
//    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
